package com.atguigu.spzx.gateway.config;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;

import java.util.stream.Collectors;

/**
 * 解决新的网关中默认没有springboot的MessageConvert，为了openFeign远程调用需要整合进来
 * feign.codec.EncodeException: No qualifying bean of type 'org.springframework.boot.autoconfigure.
 * http.HttpMessageConverters' available: expected at least 1 bean which qualifies as autowire candidate.
 * @author Mahone
 */
@Configuration
public class GatewayMessageConfig {
    @Bean
    @ConditionalOnMissingBean
    public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
        return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
    }
}